<template>
    <div class="big">
        <div class="head">
            <div class="head-title">学生个人画像</div>
            <div class="exit" @click="notFull" v-if="stuNo == null">
                <span>退出</span>
            </div>
        </div>
        <div class="echarts">
            <div class="echart person-info">
                <div class="echart-title">个人信息</div>
                <div class="info">
                    <!--  "../../../assets/big/fdy-avatar.png" -->
                    <img :src="extraForm.dailyPhoto"  alt="">
                    <div class="right">
                        <p>姓名: {{ userInfo.stuName }}</p>
                        <p>性别：{{ userInfo.sex }}</p>
                        <p>年级：{{ userInfo.gradeName }}</p>
                        <p>学院：{{ userInfo.deptName }}</p>
                        <p>班级：{{ userInfo.className }}</p>
                    </div>
                </div>
            </div>
            <div class="echart">
                <div class="echart-title">个人素质综合</div>
                <div id="quality"></div>
            </div>
            <div class="echart">
                <div class="echart-title">综合素质分数</div>
                <div id="grade"></div>
            </div>
            <div class="echart grade">
                <div class="echart-title">个人课程成绩</div>
                <div class="grade-list">
                    <div class="item" v-for="(item, index) in courseList" :key="index">
                        <img src="../../../assets/big/icon.png" alt="">
                        <div>
                            <span>{{ item.cj }}</span>
                            <span>{{ item.courseName }}</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="echart">
                <div class="echart-title">专业排名</div>
                <div id="ranking"></div>
            </div>
            <div class="echart">
                <div class="echart-title">本学期课表</div>
                <div class="schedule">
                    <table>
                        <tbody>
                            <tr>
                                <td>任课教师</td>
                                <td>课程名称</td>
                                <td>课程起始周</td>
                            </tr>
                            <tr v-for="(item, index) in myCourse" :key="index">
                                <td>{{ item.teacherName }}</td>
                                <td>{{ item.courseName }}</td>
                                <td>{{ item.zc }}</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { nowTime } from '../../../utils/index.js';
import { getUserProfile } from "@/api/system/user";
import { listOwnFive, listStuFive } from "@/api/stuCQS/info-fill/cqScore";
import { getOwnInfo, getStuInfo } from "@/api/stuCQS/basedata/stuInfoView";
import { getOwnInfo as getExtraInfo, } from "@/api/stuCQS/basedata/extraInfo";
import { listCourseScore } from "@/api/stuCQS/basedata/course";
export default {
    props: {
        stuNo: {
            type: String
        }
    },
    data() {
        return {
            timing: null,
            dateDay: null,
            dateYear: null,
            dateWeek: null,
            weekday: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
            userInfo: {
                deptName: null,
                gradeName: null,
                className: null,
                userName: null,
                sex: null,
            },
            courseList: [],
            myCourse: [
                { teacherName: "张旭蕾", courseName: 'Javascript语言实习', zc: "8周~15周" },
                { teacherName: "刘莹", courseName: 'Java面向对象程序设计', zc: "1周~8周" },
                { teacherName: "罗世俊", courseName: 'Linux应用服务器管理', zc: "5周~10周" },
                { teacherName: "黄海滨", courseName: 'photoshop', zc: "9周~18周" },
                { teacherName: "石春丽", courseName: 'Web应用开发', zc: "6周~12周" },
                { teacherName: "黄绿汀", courseName: '安全教育Ⅲ', zc: "8周~18周" },
                { teacherName: "韦丹茜", courseName: '数据库程序设计', zc: "10周~18周" },
                { teacherName: "陈前军", courseName: '中外音乐鉴赏', zc: "1周~6周" },
                { teacherName: "邓永光", courseName: '微机原理及应用 ', zc: "1周~18周" },
            ],
            extraForm:[]
        }
    },
    created() {
        this.timeFn();
        this.getUserInfo();
        this.getExtraInfo();
    },
    mounted() {
        if (this.stuNo == null) {
            this.doFull();
        }
        this.qualityChart();
        this.gradeChart();
        this.rankingChart();
        this.stuTagChart();
        window.addEventListener('resize', this.handleResize);
    },
    beforeDestroy() {
        clearInterval(this.timing)
    },
    methods: {

        doFull() {
            this.$store.dispatch('app/toggleSideBarHide', true);
            document.querySelector('.navbar').style.display = "none";
            document.querySelector('.tags-view-container').style.display = "none";
        },
        notFull() {
            this.$store.dispatch('app/toggleSideBarHide', false);
            document.querySelector('.navbar').style.display = "block";
            document.querySelector('.tags-view-container').style.display = "block";
        },
        async getUserInfo() {
            if (this.stuNo == null) {
                let queryParams = {
                    stuNo: '',
                    pageNum: 1,
                    pageSize: 100
                };
                //查询个人信息
                await getOwnInfo().then(res => {
                    this.userInfo.deptName = res.data.deptName;
                    this.userInfo.gradeName = res.data.gradeName;
                    this.userInfo.className = res.data.className;
                    this.userInfo.stuName = res.data.stuName;
                    this.userInfo.sex = res.data.gender;
                    queryParams.stuNo = res.data.stuNo;
                });
                //查询课程信息
                await listCourseScore(queryParams).then(res => {
                    this.courseList = res.rows;
                });
            } else {
                let queryParams = {
                    stuNo: '',
                    pageNum: 1,
                    pageSize: 100
                };
                //查询个人信息
                await getStuInfo(this.stuNo).then(res => {
                    this.userInfo.deptName = res.data.deptName;
                    this.userInfo.gradeName = res.data.gradeName;
                    this.userInfo.className = res.data.className;
                    this.userInfo.stuName = res.data.stuName;
                    this.userInfo.sex = res.data.gender;
                    queryParams.stuNo = res.data.stuNo;
                });
                //查询课程信息
                await listCourseScore(queryParams).then(res => {
                    this.courseList = res.rows;
                });
            } 
        },
        async getExtraInfo() {
            let res = await getExtraInfo();
            console.log(res);
            if (res.code == 200) { 
                this.extraForm = {
                    ...res.data
                };  
            } 
            this.extraForm.dailyPhoto=process.env.VUE_APP_BASE_API+this.extraForm.dailyPhoto;
            //console.log(this.extraForm);
        },

        createChart(chartId, option) {
            const chart = this.$echarts.init(document.getElementById(chartId));
            chart.setOption(option);
        },
        qualityChart() {
            const option = {
                legend: {
                    icon: "circle",
                    bottom: 0,
                    textStyle: {
                        color: '#ffffff',
                        fontSize: 14
                    },
                    // 设置图例的颜色与班级线条的颜色一致
                    data: [{
                        name: '班级',
                        itemStyle: {
                            color: '#EE6666'  // 图例的颜色设置为红色，与班级线条一致
                        }
                    }, {
                        name: '个人',
                    }]
                },
                radar: {
                    indicator: [
                        { name: '第二课堂', color: '#fff' },
                        { name: '综合评价', color: '#fff' },
                        { name: '体测', color: '#fff' },
                        { name: '思想品德', color: '#fff' },
                        { name: '平均学分绩', color: '#fff' },
                    ],
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255,0.1)'
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.2)'
                        }
                    },
                    splitArea: {
                        areaStyle: {
                            opacity: 0.7
                        }
                    }
                },
                series: [
                    {
                        type: 'radar',
                        data: [
                            {
                                value: [4200, 3000, 20000, 35000, 50000, 18000],
                                name: '班级',
                                symbol: 'none',
                                lineStyle: {
                                    color: "#EE6666"  // 修改班级线条颜色为红色
                                },
                            },
                            {
                                value: [5000, 14000, 28000, 26000, 42000, 21000],
                                name: '个人',
                                symbol: 'none'
                            }
                        ]
                    }
                ]
            };
            this.createChart('quality', option);
        },
        async gradeChart() {
            let ownRecordParams = {
                pageNum: 2,
                pageSize: 5,
                stuYearId: 1
            };
            let data = []
            ///ownRecordParams
            if (this.stuNo == null) {
                let res = await listOwnFive(ownRecordParams);
                data = [...res.rows];
            } else {
                let res = await listStuFive(this.stuNo, ownRecordParams);
                data = [...res.rows];
            }
            //console.log(res);
            let typeList = [];
            let scoreList = [];

            for (let i = 0; i < data.length; i++) {

                typeList.push(data[i].typeName);
                scoreList.push(data[i].score);
            }

            const option = {
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    axisLabel: {
                        color: "white",
                        fontSize: 12,
                        rotate: 35,
                    },
                    data: [...typeList],
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {
                        color: "white",
                        fontSize: 14,
                    },
                    splitLine: {
                        lineStyle: {
                            color: '#ffffff',
                            opacity: 0.2
                        }
                    }
                },
                series: [
                    {
                        data: [
                            { value: scoreList[0], itemStyle: { color: '#4A90E2' } },
                            { value: scoreList[1], itemStyle: { color: '#50E3C2' } },
                            { value: scoreList[2], itemStyle: { color: '#5EABE1' } },
                            { value: scoreList[3], itemStyle: { color: '#7ED321' } },
                            { value: scoreList[4], itemStyle: { color: '#57D9E3' } }
                        ],
                        type: 'bar'
                    }
                ]
            }
            this.createChart('grade', option);
        },
        rankingChart() {
            const option = {
                xAxis: {
                    type: 'category',
                    data: ['第一学期', '第二学期', '第三学期', '第四学期', '第五学期', '第六学期'], // 这里填入你的数据
                    axisLabel: {
                        color: "white",
                        fontSize: 12,
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLine: {
                        onZero: false,
                    },
                    axisLabel: {
                        color: "white",
                        fontSize: 14,
                    },
                    boundaryGap: false, // 确保数据完全显示，不留空白
                    splitLine: {
                        lineStyle: {
                            color: '#ffffff',
                            type: 'dashed',
                            opacity: 0.3
                        },
                    }
                },
                series: [{
                    type: 'line',
                    itemStyle: {
                        color: "#5FD5EC"
                    },
                    areaStyle: {
                        color: "#154A89",
                        opacity: 0.5,
                    },
                    data: [56, 45, 34, 7, 20, 7],
                }],
                grid: {
                    left: 0,
                    bottom: '3%',
                    containLabel: true, // 确保标签在网格内显示，防止被遮挡
                },
            }
            this.createChart('ranking', option);
        },
        stuTagChart() {

        },
        handleResize() {
            this.$echarts.getInstanceByDom(document.getElementById('quality')).resize();
            this.$echarts.getInstanceByDom(document.getElementById('grade')).resize();
            this.$echarts.getInstanceByDom(document.getElementById('ranking')).resize();
        },
        timeFn() {
            this.timing = setInterval(() => {
                this.dateDay = nowTime(new Date(), 'HH: mm: ss')
                this.dateYear = nowTime(new Date(), 'yyyy-MM-dd')
                this.dateWeek = this.weekday[new Date().getDay()]
            }, 1000)
        },
    }
}
</script>

<style lang="scss" scoped>
html {
    font-size: 16px;
    /* 设置根字体大小为 16px */
}

.big {
    margin: 0px;
    background: url("~@/assets/big/bg.png") no-repeat;
    background-size: 100% 100%;
    min-height: 100vh;
    width: 100%;
    color: white;
    padding-bottom: 50px;

    .head {
        display: flex;
        padding: 10px 20px;
        justify-content: space-between;
        align-items: center;

        div:nth-child(1) {
            flex: 1;
            font-size: 44px;
            font-weight: bold;
            text-align: center;
        }

        .exit {
            background: url("~@/assets/big/button.png") no-repeat;
            background-size: 100% 100%;
            width: 81px;
            height: 36px;
            cursor: pointer;
            text-align: center;
            line-height: 36px;
        }
    }

    .echarts {
        display: flex;
        padding: 20px;
        flex-wrap: wrap;

        .echart {
            width: 32%;
            height: 420px;
            background: url("~@/assets/big/stubg.png") no-repeat;
            background-size: 100% 100%;
            padding: 35px 0 35px 30px;
            margin-right: 2%;
            margin-bottom: 25px;

            &:nth-child(3n) {
                margin-right: 0;
            }

            .echart-title {
                border-left: 5px solid #45A2FF;
                padding-left: 5px;
                margin-left: 5px;
                font-size: 1.2rem;
            }

            #quality,
            #grade,
            #ranking,
            #stu-tag {
                height: 90%;
                width: 95%;
            }

            &.grade {
                padding: 35px 25px 35px 30px;
            }
        }

        .person-info {

            display: flex;
            flex-direction: column;
            font-size: 1rem;


            .info {
                display: flex;
                align-items: center;
                margin-top: 25px;

                img {
                    max-width: 30%;
                    height: auto;
                    margin: 0 20px 0 20px;
                }

                .right {
                    flex: 1;

                    .classes {
                        font-size: 0.8rem;
                    }
                }
            }
        }

        .grade-list {
            display: flex;
            flex-wrap: wrap;
            max-height: 90%;
            overflow-y: auto;

            &::-webkit-scrollbar {
                display: none;
            }

            .item {
                flex-basis: 32%;
                background-color: rgba(13, 38, 90, 0.7);
                margin-top: 20px;
                display: flex;
                padding: 20px 10px;
                align-items: center;
                justify-content: space-around;
                height: 90px;
                margin-left: 1%;

                img {
                    width: 35px;
                    height: auto;
                }

                &>div {
                    display: flex;
                    flex-direction: column;

                    span:first-child {
                        font-size: 1.4rem;
                    }

                    span:last-child {
                        color: #999;
                        margin-top: 5px;
                        font-weight: lighter;
                        font-size: 14px;
                    }
                }
            }
        }



        .stu-punishment-info {
            width: 95%;
            margin-top: 30px;
            margin-left: 8px;
            border-collapse: collapse;

            tr {
                display: flex;
                line-height: 28px;
                font-size: 1rem;

                .more {
                    font-size: 12px;
                    color: #3E9DFF;
                }

                td {
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;

                    &:nth-child(1) {
                        flex: 1;
                    }

                    &:nth-child(2) {
                        flex: 2.5;
                    }

                    &:nth-child(3) {
                        flex: 1.5;
                    }

                    &:nth-child(4) {
                        flex: 1;
                        text-align: center;
                    }

                }
            }

            tr:first-child {
                color: #fff;
                margin-bottom: 8px;
            }

            tr:not(:first-child) {
                font-size: 0.8rem;
            }
        }

        .schedule {
            max-height: 100%;
            overflow-y: auto;

            &::-webkit-scrollbar {
                display: none;
            }

            table {
                width: 95%;
                margin-top: 15px;
                margin-left: 8px;

                border-collapse: collapse;
                font-size: 1rem;

                tr {
                    display: flex;
                    line-height: 40px;
                    font-size: 0.8rem;

                    &:first-child {
                        font-weight: 600;
                        font-size: 0.9rem;
                    }

                    &:not(:first-child) {
                        line-height: 50px;
                        height: 50px;
                        padding: 0 10px;
                    }

                    &:nth-child(even) {
                        background-color: rgba($color: #427DDC, $alpha: 0.1); // 为奇数行设置蓝色背景
                    }

                    td {
                        flex: 1;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;

                    }
                }
            }
        }

    }
}
</style>